---
title: "Prisma"
description: Build a self-hosted Hot Updater server with Prisma ORM.
icon: prisma
version: "v0.22.0"
---

## Installation

Install Prisma and initialize your project.

```package-install
npm install prisma @prisma/client --save-dev
```

Initialize Prisma:
```bash
npx prisma init
```

For other databases, see [Prisma's database documentation](https://www.prisma.io/docs/orm/overview/databases).

## Setup

Create a database connection file:

```typescript title="src/prisma.ts"
import { PrismaClient } from "@prisma/client";

export const prisma = new PrismaClient();
```

## Hot Updater Configuration

Create the Hot Updater instance:

```typescript title="src/hotUpdater.ts"
import { createHotUpdater } from "@hot-updater/server";
import { prismaAdapter } from "@hot-updater/server/adapters/prisma";
import { s3Storage } from "@hot-updater/aws";
import { prisma } from "./prisma";

export const hotUpdater = createHotUpdater({
  database: prismaAdapter({ prisma, provider: "sqlite" }),
  storages: [
    s3Storage({
      region: "auto",
      endpoint: process.env.R2_ENDPOINT,
      credentials: {
        accessKeyId: process.env.R2_ACCESS_KEY_ID!,
        secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
      },
      bucketName: process.env.R2_BUCKET_NAME!,
    }),
  ],
  basePath: "/hot-updater",
});
```

## Schema Generation

Generate the Prisma schema for Hot Updater tables.

```bash
npx hot-updater db generate src/hotUpdater.ts --yes
```

This command generates the schema. Copy it into your `prisma/schema.prisma` file.

<Callout>
Need to generate SQL without config? See [SQL Export](/docs/custom/database/sql-export) for standalone SQL generation with the `--sql` flag.
</Callout>

**Example schema.prisma:**
```prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

model Bundle {
  id String @db.Uuid @id
  platform String
  should_force_update Boolean
  enabled Boolean
  file_hash String
  git_commit_hash String?
  message String?
  channel String
  storage_uri String
  target_app_version String?
  fingerprint_hash String?
  metadata Json
}
```

Run migrations:
```bash
npx prisma migrate dev --name init
```

Generate Prisma Client:
```bash
npx prisma generate
```

## CLI Configuration

Configure your CLI to use this self-hosted server.

```typescript title="hot-updater.config.ts"
import { defineConfig } from "@hot-updater/core";
import { bare } from "@hot-updater/bare";
import { s3Storage } from "@hot-updater/aws";
import { standaloneRepository } from "@hot-updater/standalone";

export default defineConfig({
  build: bare(),
  storage: s3Storage({
    region: "auto",
    endpoint: process.env.R2_ENDPOINT,
    credentials: {
      accessKeyId: process.env.R2_ACCESS_KEY_ID!,
      secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
    },
    bucketName: process.env.R2_BUCKET_NAME!,
  }),
  database: standaloneRepository({
    baseUrl: "http://localhost:3000/hot-updater",
  }),
});
```

<Callout type="warn">
The `storage` plugin must match the `storages` in your server's `createHotUpdater`. Both use `s3Storage` in this example.
</Callout>

## API Endpoints

The server automatically creates these endpoints:

| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/hot-updater/version` | Get server version |
| GET | `/hot-updater/fingerprint/:platform/:fingerprintHash/:channel/:minBundleId/:bundleId` | Check for updates by fingerprint |
| GET | `/hot-updater/app-version/:platform/:version/:channel/:minBundleId/:bundleId` | Check for updates by app version |
| GET | `/hot-updater/api/bundles` | List bundles (query: channel, platform, limit, offset) |
| GET | `/hot-updater/api/bundles/:id` | Get bundle by ID |
| POST | `/hot-updater/api/bundles` | Create or update bundles |
| DELETE | `/hot-updater/api/bundles/:id` | Delete bundle |
| GET | `/hot-updater/api/bundles/channels` | List all channels |
